using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Adex
{
	/// <summary>
	/// Strongly-typed collection for the Category class.
	/// </summary>
	[Serializable]
	public partial class CategoryCollection : ActiveList<Category, CategoryCollection> 
	{	   
		public CategoryCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the Category table.
	/// </summary>
	[Serializable]
	public partial class Category : ActiveRecord<Category>
	{
		#region .ctors and Default Settings
		
		public Category()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public Category(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public Category(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public Category(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("Category", TableType.Table, DataService.GetInstance("Adex"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarCategoryID = new TableSchema.TableColumn(schema);
				colvarCategoryID.ColumnName = "CategoryID";
				colvarCategoryID.DataType = DbType.Int32;
				colvarCategoryID.MaxLength = 0;
				colvarCategoryID.AutoIncrement = true;
				colvarCategoryID.IsNullable = false;
				colvarCategoryID.IsPrimaryKey = true;
				colvarCategoryID.IsForeignKey = false;
				colvarCategoryID.IsReadOnly = false;
				colvarCategoryID.DefaultSetting = @"";
				colvarCategoryID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCategoryID);
				
				TableSchema.TableColumn colvarCategoryCode = new TableSchema.TableColumn(schema);
				colvarCategoryCode.ColumnName = "CategoryCode";
				colvarCategoryCode.DataType = DbType.Int32;
				colvarCategoryCode.MaxLength = 0;
				colvarCategoryCode.AutoIncrement = false;
				colvarCategoryCode.IsNullable = false;
				colvarCategoryCode.IsPrimaryKey = false;
				colvarCategoryCode.IsForeignKey = false;
				colvarCategoryCode.IsReadOnly = false;
				colvarCategoryCode.DefaultSetting = @"";
				colvarCategoryCode.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCategoryCode);
				
				TableSchema.TableColumn colvarCategoryName = new TableSchema.TableColumn(schema);
				colvarCategoryName.ColumnName = "CategoryName";
				colvarCategoryName.DataType = DbType.String;
				colvarCategoryName.MaxLength = 255;
				colvarCategoryName.AutoIncrement = false;
				colvarCategoryName.IsNullable = true;
				colvarCategoryName.IsPrimaryKey = false;
				colvarCategoryName.IsForeignKey = false;
				colvarCategoryName.IsReadOnly = false;
				colvarCategoryName.DefaultSetting = @"";
				colvarCategoryName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCategoryName);
				
				TableSchema.TableColumn colvarSubSectorID = new TableSchema.TableColumn(schema);
				colvarSubSectorID.ColumnName = "SubSectorID";
				colvarSubSectorID.DataType = DbType.Int32;
				colvarSubSectorID.MaxLength = 0;
				colvarSubSectorID.AutoIncrement = false;
				colvarSubSectorID.IsNullable = true;
				colvarSubSectorID.IsPrimaryKey = false;
				colvarSubSectorID.IsForeignKey = true;
				colvarSubSectorID.IsReadOnly = false;
				colvarSubSectorID.DefaultSetting = @"";
				
					colvarSubSectorID.ForeignKeyTableName = "SubSector";
				schema.Columns.Add(colvarSubSectorID);
				
				TableSchema.TableColumn colvarMediaType = new TableSchema.TableColumn(schema);
				colvarMediaType.ColumnName = "MediaType";
				colvarMediaType.DataType = DbType.String;
				colvarMediaType.MaxLength = 5;
				colvarMediaType.AutoIncrement = false;
				colvarMediaType.IsNullable = true;
				colvarMediaType.IsPrimaryKey = false;
				colvarMediaType.IsForeignKey = false;
				colvarMediaType.IsReadOnly = false;
				colvarMediaType.DefaultSetting = @"";
				colvarMediaType.ForeignKeyTableName = "";
				schema.Columns.Add(colvarMediaType);
				
				TableSchema.TableColumn colvarTv = new TableSchema.TableColumn(schema);
				colvarTv.ColumnName = "TV";
				colvarTv.DataType = DbType.Boolean;
				colvarTv.MaxLength = 0;
				colvarTv.AutoIncrement = false;
				colvarTv.IsNullable = false;
				colvarTv.IsPrimaryKey = false;
				colvarTv.IsForeignKey = false;
				colvarTv.IsReadOnly = false;
				
						colvarTv.DefaultSetting = @"((0))";
				colvarTv.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTv);
				
				TableSchema.TableColumn colvarRd = new TableSchema.TableColumn(schema);
				colvarRd.ColumnName = "RD";
				colvarRd.DataType = DbType.Boolean;
				colvarRd.MaxLength = 0;
				colvarRd.AutoIncrement = false;
				colvarRd.IsNullable = false;
				colvarRd.IsPrimaryKey = false;
				colvarRd.IsForeignKey = false;
				colvarRd.IsReadOnly = false;
				
						colvarRd.DefaultSetting = @"((0))";
				colvarRd.ForeignKeyTableName = "";
				schema.Columns.Add(colvarRd);
				
				TableSchema.TableColumn colvarCb = new TableSchema.TableColumn(schema);
				colvarCb.ColumnName = "CB";
				colvarCb.DataType = DbType.Boolean;
				colvarCb.MaxLength = 0;
				colvarCb.AutoIncrement = false;
				colvarCb.IsNullable = false;
				colvarCb.IsPrimaryKey = false;
				colvarCb.IsForeignKey = false;
				colvarCb.IsReadOnly = false;
				
						colvarCb.DefaultSetting = @"((0))";
				colvarCb.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCb);
				
				TableSchema.TableColumn colvarPr = new TableSchema.TableColumn(schema);
				colvarPr.ColumnName = "PR";
				colvarPr.DataType = DbType.Boolean;
				colvarPr.MaxLength = 0;
				colvarPr.AutoIncrement = false;
				colvarPr.IsNullable = false;
				colvarPr.IsPrimaryKey = false;
				colvarPr.IsForeignKey = false;
				colvarPr.IsReadOnly = false;
				
						colvarPr.DefaultSetting = @"((0))";
				colvarPr.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPr);
				
				TableSchema.TableColumn colvarOd = new TableSchema.TableColumn(schema);
				colvarOd.ColumnName = "OD";
				colvarOd.DataType = DbType.Boolean;
				colvarOd.MaxLength = 0;
				colvarOd.AutoIncrement = false;
				colvarOd.IsNullable = false;
				colvarOd.IsPrimaryKey = false;
				colvarOd.IsForeignKey = false;
				colvarOd.IsReadOnly = false;
				
						colvarOd.DefaultSetting = @"((0))";
				colvarOd.ForeignKeyTableName = "";
				schema.Columns.Add(colvarOd);
				
				TableSchema.TableColumn colvarNs = new TableSchema.TableColumn(schema);
				colvarNs.ColumnName = "NS";
				colvarNs.DataType = DbType.Boolean;
				colvarNs.MaxLength = 0;
				colvarNs.AutoIncrement = false;
				colvarNs.IsNullable = false;
				colvarNs.IsPrimaryKey = false;
				colvarNs.IsForeignKey = false;
				colvarNs.IsReadOnly = false;
				
						colvarNs.DefaultSetting = @"((0))";
				colvarNs.ForeignKeyTableName = "";
				schema.Columns.Add(colvarNs);
				
				TableSchema.TableColumn colvarDateAdded = new TableSchema.TableColumn(schema);
				colvarDateAdded.ColumnName = "DateAdded";
				colvarDateAdded.DataType = DbType.DateTime;
				colvarDateAdded.MaxLength = 0;
				colvarDateAdded.AutoIncrement = false;
				colvarDateAdded.IsNullable = false;
				colvarDateAdded.IsPrimaryKey = false;
				colvarDateAdded.IsForeignKey = false;
				colvarDateAdded.IsReadOnly = false;
				
						colvarDateAdded.DefaultSetting = @"(getdate())";
				colvarDateAdded.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDateAdded);
				
				TableSchema.TableColumn colvarDateModified = new TableSchema.TableColumn(schema);
				colvarDateModified.ColumnName = "DateModified";
				colvarDateModified.DataType = DbType.DateTime;
				colvarDateModified.MaxLength = 0;
				colvarDateModified.AutoIncrement = false;
				colvarDateModified.IsNullable = false;
				colvarDateModified.IsPrimaryKey = false;
				colvarDateModified.IsForeignKey = false;
				colvarDateModified.IsReadOnly = false;
				
						colvarDateModified.DefaultSetting = @"(getdate())";
				colvarDateModified.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDateModified);
				
				TableSchema.TableColumn colvarInX = new TableSchema.TableColumn(schema);
				colvarInX.ColumnName = "IN";
				colvarInX.DataType = DbType.Boolean;
				colvarInX.MaxLength = 0;
				colvarInX.AutoIncrement = false;
				colvarInX.IsNullable = false;
				colvarInX.IsPrimaryKey = false;
				colvarInX.IsForeignKey = false;
				colvarInX.IsReadOnly = false;
				
						colvarInX.DefaultSetting = @"((0))";
				colvarInX.ForeignKeyTableName = "";
				schema.Columns.Add(colvarInX);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["Adex"].AddSchema("Category",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("CategoryID")]
		public int CategoryID 
		{
			get { return GetColumnValue<int>("CategoryID"); }

			set { SetColumnValue("CategoryID", value); }

		}

		  
		[XmlAttribute("CategoryCode")]
		public int CategoryCode 
		{
			get { return GetColumnValue<int>("CategoryCode"); }

			set { SetColumnValue("CategoryCode", value); }

		}

		  
		[XmlAttribute("CategoryName")]
		public string CategoryName 
		{
			get { return GetColumnValue<string>("CategoryName"); }

			set { SetColumnValue("CategoryName", value); }

		}

		  
		[XmlAttribute("SubSectorID")]
		public int? SubSectorID 
		{
			get { return GetColumnValue<int?>("SubSectorID"); }

			set { SetColumnValue("SubSectorID", value); }

		}

		  
		[XmlAttribute("MediaType")]
		public string MediaType 
		{
			get { return GetColumnValue<string>("MediaType"); }

			set { SetColumnValue("MediaType", value); }

		}

		  
		[XmlAttribute("Tv")]
		public bool Tv 
		{
			get { return GetColumnValue<bool>("TV"); }

			set { SetColumnValue("TV", value); }

		}

		  
		[XmlAttribute("Rd")]
		public bool Rd 
		{
			get { return GetColumnValue<bool>("RD"); }

			set { SetColumnValue("RD", value); }

		}

		  
		[XmlAttribute("Cb")]
		public bool Cb 
		{
			get { return GetColumnValue<bool>("CB"); }

			set { SetColumnValue("CB", value); }

		}

		  
		[XmlAttribute("Pr")]
		public bool Pr 
		{
			get { return GetColumnValue<bool>("PR"); }

			set { SetColumnValue("PR", value); }

		}

		  
		[XmlAttribute("Od")]
		public bool Od 
		{
			get { return GetColumnValue<bool>("OD"); }

			set { SetColumnValue("OD", value); }

		}

		  
		[XmlAttribute("Ns")]
		public bool Ns 
		{
			get { return GetColumnValue<bool>("NS"); }

			set { SetColumnValue("NS", value); }

		}

		  
		[XmlAttribute("DateAdded")]
		public DateTime DateAdded 
		{
			get { return GetColumnValue<DateTime>("DateAdded"); }

			set { SetColumnValue("DateAdded", value); }

		}

		  
		[XmlAttribute("DateModified")]
		public DateTime DateModified 
		{
			get { return GetColumnValue<DateTime>("DateModified"); }

			set { SetColumnValue("DateModified", value); }

		}

		  
		[XmlAttribute("InX")]
		public bool InX 
		{
			get { return GetColumnValue<bool>("IN"); }

			set { SetColumnValue("IN", value); }

		}

		
		#endregion
		
		
		#region PrimaryKey Methods
		
		public Adex.CompanyCategoryCollection CompanyCategoryRecords()
		{
			return new Adex.CompanyCategoryCollection().Where(CompanyCategory.Columns.CategoryCode, CategoryID).Load();
		}

		public Adex.CompanyNewCommercialCategoryCollection CompanyNewCommercialCategoryRecords()
		{
			return new Adex.CompanyNewCommercialCategoryCollection().Where(CompanyNewCommercialCategory.Columns.NewCommercialCategoryCode, CategoryID).Load();
		}

		#endregion
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a SubSector ActiveRecord object related to this Category
		/// 
		/// </summary>
		public Adex.SubSector SubSector
		{
			get { return Adex.SubSector.FetchByID(this.SubSectorID); }

			set { SetColumnValue("SubSectorID", value.SubSectorID); }

		}

		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int varCategoryCode,string varCategoryName,int? varSubSectorID,string varMediaType,bool varTv,bool varRd,bool varCb,bool varPr,bool varOd,bool varNs,DateTime varDateAdded,DateTime varDateModified,bool varInX)
		{
			Category item = new Category();
			
			item.CategoryCode = varCategoryCode;
			
			item.CategoryName = varCategoryName;
			
			item.SubSectorID = varSubSectorID;
			
			item.MediaType = varMediaType;
			
			item.Tv = varTv;
			
			item.Rd = varRd;
			
			item.Cb = varCb;
			
			item.Pr = varPr;
			
			item.Od = varOd;
			
			item.Ns = varNs;
			
			item.DateAdded = varDateAdded;
			
			item.DateModified = varDateModified;
			
			item.InX = varInX;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varCategoryID,int varCategoryCode,string varCategoryName,int? varSubSectorID,string varMediaType,bool varTv,bool varRd,bool varCb,bool varPr,bool varOd,bool varNs,DateTime varDateAdded,DateTime varDateModified,bool varInX)
		{
			Category item = new Category();
			
				item.CategoryID = varCategoryID;
				
				item.CategoryCode = varCategoryCode;
				
				item.CategoryName = varCategoryName;
				
				item.SubSectorID = varSubSectorID;
				
				item.MediaType = varMediaType;
				
				item.Tv = varTv;
				
				item.Rd = varRd;
				
				item.Cb = varCb;
				
				item.Pr = varPr;
				
				item.Od = varOd;
				
				item.Ns = varNs;
				
				item.DateAdded = varDateAdded;
				
				item.DateModified = varDateModified;
				
				item.InX = varInX;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string CategoryID = @"CategoryID";
			 public static string CategoryCode = @"CategoryCode";
			 public static string CategoryName = @"CategoryName";
			 public static string SubSectorID = @"SubSectorID";
			 public static string MediaType = @"MediaType";
			 public static string Tv = @"TV";
			 public static string Rd = @"RD";
			 public static string Cb = @"CB";
			 public static string Pr = @"PR";
			 public static string Od = @"OD";
			 public static string Ns = @"NS";
			 public static string DateAdded = @"DateAdded";
			 public static string DateModified = @"DateModified";
			 public static string InX = @"IN";
						
		}

		#endregion
	}

}

